package yuznu;

import java.util.ArrayList;

class studentManager {
    private ArrayList<Student> students = new ArrayList<>();

    //添加学生
    public void addStudent(Student student) {
        students.add(student);
        System.out.println("学生信息添加成功");
    }

    //删除学生
    public void deleteStudent(int id) {
        for (int i = 0; i < students.size(); i++) {
            if (students.get(i).getId() == id) {
                students.remove(i);
                System.out.println("学生删除成功！");
                return;
            }
        }
        System.out.println("未找到学生id,删除失败");
    }

    //修改学生
    public void updateStudent(int id, String name, String class1, String sex) {
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            if (student.getId() == id) {
                student.setName(name);
                student.setClass1(class1);
                student.setSex(sex);
                System.out.println("数据更新成功");
                return;
            }
        }
        System.out.println("未找到该学生信息,更新失败");
    }

    //查看学生
    public void selectStudent(int id) {
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            if (student.getId() == id) {
                System.out.println(student);
                return;
            }
        }
        System.out.println("找不到该学生信息");
    }
    //查看所有学生信息
    public void showStudent() {
        for (int i = 0; i < students.size(); i++) {
            Student student = students.get(i);
            System.out.println(student);
        }
    }
}
